/**
 *
 *
 * EShow JS 公共组件库
 * 由于该组件应用于eshow后台，依赖jquery;
 *
 *
 */



var ESUtils = {
    /**
     * 加载css
     * @param  url
     */
    loadStyles:function(url) {
        var link = document.createElement("link");
        link.type = "text/css";
        link.rel = "stylesheet";
        link.href = url;
        document.getElementsByTagName("head")[0].appendChild(link);
    }
    ,

    /**
     * 操作反馈提示消息
     * @param msg,type,time
     */
    alert:function(msg,type,time){
        var _class="";
        if(type=='1'||type==1){
            _class="ESmsg-success";
        }else{
            _class="ESmsg-danger";
        }
        var tmpl='<div class="ESmsg animated '+_class+'" role="alert"><span>{content}</span></div>';
        tmpl = tmpl.replace("{content}", msg);
        $('body').append(tmpl);
        $(".ESmsg").addClass("bounce");
        window.setTimeout(ESUtils.removemsg,time*1000);
    },
    removemsg:function () {
        $(".ESmsg").addClass("fadeOutUp");
    }
    ,
    /**
     * 操作前一天后一天
     * @param asday,i
     */
    GetDay:function(asday, i)
        {

            str = asday.replace(/-/g,"/");
            var today=new Date(str);
            var yesterday_milliseconds=today.getTime()+i*1000*60*60*24;
            var yesterday=new Date();
            yesterday.setTime(yesterday_milliseconds);

            var strYear=yesterday.getFullYear();
            var strDay=yesterday.getDate();
            var strMonth=yesterday.getMonth()+1;
            if(strMonth<10)
            {
                strMonth="0"+strMonth;
            }
            var strYesterday=strYear+"-"+strMonth+"-"+strDay;
            return strYesterday;
        },
        /**
         * 操作前一月后一月
         * @param sDate,num
         */
        addMonth:function(sDate,i) {
                var aYmd = sDate.split('-');
                var dt = new Date(aYmd[0],aYmd[1]);
                dt.setMonth(dt.getMonth() + i*1);
                var y = dt.getFullYear();
                var m = dt.getMonth();
                var d = dt.getDate();
                if (m == 0) { m = 12; y = y - 1; }
                if (m < 10) m = '0' + m;
                if (d < 10) d = '0' + d;
                return y + '-' + m;
            },
        /**
         * 操作前一年后一年
         * @param
         */
        addyear:function(y,i) {
            var _year = y*1+i*1;
            return _year;
        }

}



/**
	* 加载依赖css文件
	* @param 
	*/
ESUtils.loadStyles("http://static.eshow.org.cn/EShow-libs/css/eshow.css");//基础样式
ESUtils.loadStyles("http://static.eshow.org.cn/EShow-libs/css/animate.min.css");//动效




